import { defineStore } from "pinia";
export type Tab = {
  title: string;
  path: string;
};
export type TabState = {
  tabList: Tab[];
};
export const tabsStore = defineStore("tabsStore", {
  state: (): TabState => {
    return {
      tabList: [],
    };
  },
  actions: {
    addTab(tab: Tab) {
      if (this.tabList.some((item) => item.path === tab.path)) return;
      if (tab.path === "/dashboard") {
        this.tabList.unshift(tab);
      } else {
        this.tabList.push(tab);
      }
    },
  },
  getters: {
    getTab: (state) => state.tabList,
  },
  persist: {
    key: "tabList",
    storage: localStorage,
  },
});
